# coding=utf-8
from exs import db


class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50), nullable=False)
    password = db.Column(db.String(50), nullable=True)
    email = db.Column(db.String(50))
    role_id = db.Column(db.Integer, db.ForeignKey('role.id'), nullable=False)

    def __repr__(self):
        return self.username


class Role(db.Model):
    __tablename__ = 'role'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    role_name = db.Column(db.String(50), nullable=False)
    role_statu = db.Column(db.Boolean, default=True)
    users = db.relationship('User', backref='role', lazy='dynamic')

    def __repr__(self):
        return "%s ---%s" % (self.role_name, self.role_statu)
